﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using ZLDC.Common.Estate;

namespace ZLDC.Estate.Quantify.workurl
{
    public partial class lp_myListUrl : System.Web.UI.Page
    {
        public StringBuilder sb = new StringBuilder();
        public int j = 0;
        public string userid = "0";
        public string username = "0";
        protected void Page_Load(object sender, EventArgs e)
        {
            userid = _Request.GetString("uesrid", "0");
            username = _Request.GetString("username", "");
            if (!IsPostBack)
            {

                if (ZLDC.Topo.BLL.Estate.lp_Basis.GetStationhz(_Utility.GetInfoBySession().m_sStation))
                {
                    userid = _Utility.GetInfoBySession().m_sUserID;
                    GetList(_Utility.GetInfoBySession().m_sUserID);
                }
                else
                {
                    GetUserList();
                    
                    GetList(userid);
                }
            }
        }

        /// <summary>
        /// 显示员工列表
        /// </summary>
        protected void GetUserList()
        {
            string sql = ZLDC.Topo.BLL.Estate.lp_myListUrl.GetstringUserlist(_Utility.GetInfoBySession().m_sDeptID, "0");
            DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql);

            string divuserlist = ZLDC.Topo.BLL.Estate.lp_myListUrl.returnList(ds);
            div1.InnerHtml = divuserlist;
        }


        protected void GetList(string userid)
        {
            DataSet ds = new DataSet();

            ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds("select * from lp_WorkUrl where UserID=" + userid + " ");
            j = ds.Tables[0].Rows.Count;

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                sb.Append("<tr>");
                sb.Append("<td>");
                sb.Append("<input type=\"text\" class=\"txtwidth\"  name=\"txtTypeName\" value='" + ds.Tables[0].Rows[i]["TypeName"] + "' />");
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append("<input type=\"text\"  name=\"txtUrl\" value='" + ds.Tables[0].Rows[i]["Url"] + "' />");
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append("<input type=\"text\" class=\"txtwidth\" name=\"txtRemark\"  value='" + ds.Tables[0].Rows[i]["Remark"] + "' />");
                sb.Append("</td>");
                sb.Append("<td>");
                sb.Append("<input    type='button'  value='删除' onclick=\"delRow(this,'tb1')\" />");
                sb.Append("</td>");
                sb.Append("<tr>");
            }

        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (Request.Form["txtTypeName"] != null)
            {
                string[] txtTypeName = Request.Form["txtTypeName"].Split(',');
                string[] txtUrl = Request.Form["txtUrl"].Split(',');
                string[] txtRemark = Request.Form["txtRemark"].Split(',');
                string deptid1 = _Utility.GetInfoBySession().m_sDeptID;
                string userid1 = _Utility.GetInfoBySession().m_sUserID;
                string useridname1 = _Utility.GetInfoBySession().m_sUserName;
                if (userid != "0")
                {
                    userid1 = userid;
                    useridname1 = username;
                }
                string msg = ZLDC.Topo.BLL.Estate.lp_myListUrl.SqlQuery(txtTypeName, txtUrl, txtRemark, deptid1, userid1, useridname1);
                Response.Write("<script>alert('" + msg + "');window.location.href=location.href;</script>");
            }
        }
    }
}
